package com.dao;

import com.beans.AdminInfo;
import com.beans.GoodsInfo;
import com.beans.MenuInfo;
import com.beans.PageInfo;
import com.jdbc.DBUtil;

import java.util.List;

public class GoodsDao {
    /**
     * 检查商品名是否重复
     * @param goodsName 商品名
     * @return 商品实体类对象
     */
    public GoodsInfo checkGoodsName(String goodsName) {
        String sql = "select * from goodsInfo where goodsName=?";
        return DBUtil.getSingleObject(sql,GoodsInfo.class,goodsName);
    }

    /**
     * 根据商品id查询商品信息
     * @param goodsId 商品id
     * @return 商品实体类对象
     */
    public GoodsInfo getGoodsById(int goodsId) {
        String sql = "select * from goodsInfo where id=?";
        return DBUtil.getSingleObject(sql,GoodsInfo.class,goodsId);
    }
    //添加商品
    public int addGoods(GoodsInfo goods) {
        Object[] o = {
          goods.getGoodsName(),
          goods.getBigCateId(),
          goods.getSmallCateId(),
          goods.getPrice(),
          goods.getDes(),
          goods.getUnit(),
          goods.getProductor(),
          goods.getPictureData(),
        };
        String sql = "insert into goodsInfo(goodsName,bigCateId,smallCateId,price,des,unit,producter,pictureData) values(?,?,?,?,?,?,?,?)";
        return DBUtil.addAndReturnId(sql,o);
    }

    /**
     * 获取商品的总数
     * @return 返回商品数
     */
    public int getGoodsCount() {
        String sql="select count(*) from goodsInfo";
        long count= DBUtil.getScalar(sql);
        return Integer.parseInt(count+"");
    }

    /**
     * 获取所有商品的信息（带分页）
     * @param page 分页信息
     * @return 所有商品信息
     */
    public List<GoodsInfo> getGoodsList(PageInfo page) {
      return null;
    }
}
